//+------------------------------------------------------------------+ //| SupportResistTrade.mq4 | //| Copyright © 2008, Gryb Alexander | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Gryb Alexander" #property link "" extern int MagicNumber = 12345; extern int numBars = 55; extern int maPeriod = 500; extern int Lots = 1; extern double TrailingStop = 50; double support; double resist; string trendType; int timeFrame = 1; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- ObjectCreate("lineSupport",OBJ_HLINE,0,0,0); ObjectSet("lineSupport",OBJPROP_COLOR,Blue); ObjectCreate("lineResist",OBJ_HLINE,0,0,0); ObjectSet("lineResist",OBJPROP_COLOR,Red); ObjectCreate("lblTrendType",OBJ_LABEL,0,0,0,0,0); ObjectSet("lblTrendType",OBJPROP_XDISTANCE,50); ObjectSet("lblTrendType",OBJPROP_YDISTANCE,50); ObjectSetText("lblTrendType","TrendType",14,"Tahoma",Red); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- DeleteMyObjects(); //---- return(0); } void DeleteMyObjects() { int obj = ObjectsTotal(); string objName; if (obj > 0) { for (int i = obj; i >= 0;i--) { objName = ObjectName(i); if (objName == "lblTrendType") { ObjectDelete(objName); continue; } if (objName == "lineSupport") { ObjectDelete(objName); continue; } if (objName == "lineResist") { ObjectDelete(objName); continue; } } } } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int NumOrders; //---- MarketAnalize(); NumOrders = CalculateCurrentOrders(); if(NumOrders == 0) CheckForOpen(); else CheckForClose(); //---- return(0); } int CalculateCurrentOrders() { int buys = 0, sells = 0, num = 0; for(int i=0;iiLow(Symbol(),timeFrame,k)) support = iLow(Symbol(),timeFrame,k); if(resistma) { trendType = "bullish"; } if(Open[0]resist) OrderSend(Symbol(),OP_BUY,Lots,Ask,3,support,0,"Support & Resistance trader",MagicNumber,0,Green); } if(trendType=="bearish") { if(Bid= 0;i--) { OrderSelect(i,SELECT_BY_POS); if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != MagicNumber) continue; if(OrderProfit()>0) { if(OrderType()==OP_BUY) { if(Bidresist) OrderClose(OrderTicket(),OrderLots(),Ask,3); } } //Trailing if(OrderType()==OP_BUY) { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()OrderOpenPrice()+Point*20)&&(OrderStopLoss()<(OrderOpenPrice()+Point*10))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*10,OrderTakeProfit(),0,Blue); // if((Ask>OrderOpenPrice()+Point*40)&&(OrderStopLoss()<(OrderOpenPrice()+Point*20))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*20,OrderTakeProfit(),0,Blue); // if((Ask>OrderOpenPrice()+Point*60)&&(OrderStopLoss()<(OrderOpenPrice()+Point*30))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*30,OrderTakeProfit(),0,Blue); // } if(OrderType()==OP_SELL) { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } // if((Bid(OrderOpenPrice()-Point*10))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*10,OrderTakeProfit(),0,Blue); // if((Bid(OrderOpenPrice()-Point*20))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*20,OrderTakeProfit(),0,Blue); // if((Bid(OrderOpenPrice()-Point*30))) // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*30,OrderTakeProfit(),0,Blue); } } }